package com.api.shopapi.mapper;


import com.api.shopapi.entity.ElderlyClockin;
import com.api.shopapi.entity.dto.ElderlyClockinDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Mapper
@Repository
public interface ElderlyClockinMapper {

    @Insert("insert into elderly_clockin " +
            "(" +
            "ElderlyClockinCode," +
            "ElderlyCode," +
            "ImgUrl," +
            "CreateTime," +
            "GovernmentCode," +
            "Lon," +
            "Lat," +
            "Address," +
            "ServeCode," +
            "IdCard," +
            "ZoneCodePath," +
            "ZoneCode," +
            "Remark" +
            ") " +
            "VALUES" +
            "(" +
            "#{elderlyClockin.ElderlyClockinCode}," +
            "#{elderlyClockin.ElderlyCode}," +
            "#{elderlyClockin.ImgUrl}," +
            "#{elderlyClockin.CreateTime}," +
            "#{elderlyClockin.GovernmentCode},"+
            "#{elderlyClockin.Lon}," +
            "#{elderlyClockin.Lat}," +
            "#{elderlyClockin.Address}," +
            "#{elderlyClockin.ServeCode}," +
            "#{elderlyClockin.IdCard}," +
            "#{elderlyClockin.ZoneCodePath}," +
            "#{elderlyClockin.ZoneCode}," +
            "#{elderlyClockin.Remark}" +
            ")")
    public int insert(@Param("elderlyClockin") ElderlyClockin elderlyClockin);


    //老人打卡记录列表
    @Select("<script>" +
            "select ec.* from elderly_clockin  ec left join elderly e on ec.ElderlyCode=e.ElderlyCode" +
            " where ec.GovernmentCode=#{governmentCode} " +
            " and (ec.CreateTime between #{startTime} and #{endTime})   " +
            "<if test =' zoneCode !=\"00000000-0000-0000-0000-000000000000\" '>" +
            " and instr(ec.ZoneCodePath,#{zoneCode})>0 " +
            "</if>" +
            "<if test ='idCard !=null and  idCard!=\"\" '> " +
            " and  ec.IdCard =#{idCard} " +
            "</if>" +
            "<if test ='name !=null and  name!=\"\" '> " +
            " and  e.Name =#{name} " +
            "</if>" +
            " order by ec.CreateTime desc " +
            "</script>")
    List<ElderlyClockinDTO> getPageList(@Param("governmentCode") String governmentCode,
                                        @Param("zoneCode") String zoneCode,
                                        @Param("startTime") Date startTime,
                                        @Param("endTime") Date endTime,
                                        @Param("idCard") String idCard,
                                        @Param("name")String name);


    //获取服务人员的打开记录
    @Select("select * from elderly_clockin where serveCode =#{serveCode} order by CreateTime desc ")
    List<ElderlyClockinDTO> getForPageForServe(@Param("serveCode") String serveCode);

}
